package com.mooral.bean;

import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;

public class Category extends Bean {

	protected String objectType = "Category";
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2836267512190756155L;

	
	protected Categories childs = new Categories();

	public boolean addChild(Category child){
		return childs.add(child);
	}
	
	public Categories getChilds(){
		return childs;
	}
	
	public boolean hasChilds(){
		if(childs == null) return false;
		return (childs.size()>0);
	}
	
	public Collection getChildsIds(){
		Vector childsIds = new Vector();
		Iterator iterator = getChilds().iterator();
		if(hasChilds()){
			while(iterator.hasNext()){
				Category category = (Category) iterator.next();
				childsIds.add(category.get("id"));
				if(category.hasChilds())
					childsIds.addAll(category.getChildsIds());
			}		
		}
		return childsIds;
	}
}